﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;

using XMK.Framework.DataAccess;
using XMK.Tadong.Model;
using XMK.Utils;
using XMK.Framework.Model;
using XMK.Tadong.Model.Cond;
using System.IO;

namespace XMK.Tadong.Data
{
    public class Base_RM_UserInfoData
    {

        /// <summary>
        /// 数据库连接
        /// </summary>
        protected DbProvider dbProvider;

        public Base_RM_UserInfoData(DbProvider dbProvider)
        {
            this.dbProvider = dbProvider;
        }

        public DataTable QueryAllUser()
        {
            string selectSql = @"select a.user_id, a.user_account,
                                     a.user_name,
                                     case a.user_sex
                                       when 1 then
                                        '男'
                                       else
                                        '女'
                                     end USER_SEX
                                from base_userinfo a";
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, selectSql);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            return DbManager.ExecuteDataTable(cmd);
        }

        #region 部门
        /// <summary>
        /// 职工组织机构列表提取
        /// </summary>
        /// <returns></returns>
        public List<Base_OrganizationInfo> GetStaffOrganizeList()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT Organization_ID,Organization_Name,ParentId,'0' AS isUser FROM Base_Organization UNION ALL SELECT U.User_ID AS Organization_ID ,U.User_Code || '|' || U.User_Name AS User_Name,S.Organization_ID,'1' AS isUser FROM Base_UserInfo U RIGHT JOIN Base_StaffOrganize S ON U.User_ID = S.User_ID");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            List<Base_OrganizationInfo> staffOrgList = DbManager.GetInfoList<Base_OrganizationInfo>(cmd,
                delegate(out Base_OrganizationInfo staffOrg, DataRow row)
                {
                    staffOrg = new Base_OrganizationInfo
                    {
                        ORGANIZATION_ID = ParseHelper.Parse<string>(row["Organization_ID"]),
                        ORGANIZATION_NAME = ParseHelper.Parse<string>(row["Organization_Name"]),
                        PARENTID = ParseHelper.Parse<string>(row["ParentId"]),
                        IsUser = ParseHelper.Parse<string>(row["isUser"]).Equals("0") ? false : true
                    };
                });
            return staffOrgList;
        }
        public DataSet QueryUserByTeam(string teamId)
        {
            DataSet ds = new DataSet();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("Select USER_ID,USER_CODE,USER_ACCOUNT,USER_NAME,USER_REMARK from Base_UserInfo  ");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable dt = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            dt.TableName = "dt";
            strSql.Clear();
            strSql.Append("select USER_ID,DATAADMIN from tb_team_user where team_id= " + teamId);
            cmd = new DbCmdHelper(dbProvider, strSql.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable dt1 = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            dt1.TableName = "dt1";
            ds.Tables.Add(dt.Copy());
            ds.Tables.Add(dt1.Copy());
            return ds;
        }

        public DataTable QueryTeamUserByTeam(string teamId)
        {
            DataSet ds = new DataSet();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("Select Base_UserInfo.USER_ID,Base_UserInfo.USER_CODE,Base_UserInfo.USER_ACCOUNT,Base_UserInfo.USER_NAME,Base_UserInfo.USER_REMARK,tb_team_user.dataadmin from Base_UserInfo inner join tb_team_user on Base_UserInfo.User_Id=tb_team_user.user_id where tb_team_user.team_id=" + teamId);
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable dt = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            return dt;
        }

        /// <summary>
        /// 批量修改课题组用户
        /// </summary>
        /// <param name="teamid"></param>
        /// <param name="users"></param>
        /// <returns></returns>
        public bool EditTeamInfo(string teamid, string userid)
        {
           
            try
            {
               
                StringBuilder strSql = new StringBuilder();
                strSql.Append("insert into  TB_TEAM_USER(TEAM_ID,USER_ID) values (" + teamid + ",'" + userid + "')");
                DbCmdHelper cmd1 = new DbCmdHelper(dbProvider, strSql.ToString());

                cmd1.DbCmdInfo.CommandType = CommandType.Text;
                return DbManager.ExecTrans(cmd1.DbProvider, cmd1.DbCmdInfo);
                
            }
            catch (Exception e) 
            {
                return false;
            }
            

        }
        /// <summary>
        /// 删除课题组用户
        /// </summary>
        /// <param name="teamid"></param>
        /// <param name="users"></param>
        /// <returns></returns>
        public bool deleteTeamUserByUserId(string userid)
        {

            try
            {

                StringBuilder strSql = new StringBuilder();
                strSql.Append("delete from tb_team_user where user_id='"+userid+"'");
                DbCmdHelper cmd1 = new DbCmdHelper(dbProvider, strSql.ToString());

                cmd1.DbCmdInfo.CommandType = CommandType.Text;
                return DbManager.ExecTrans(cmd1.DbProvider, cmd1.DbCmdInfo);

            }
            catch (Exception e)
            {
                return false;
            }


        }
        /// <summary>
        /// 批量修改课题组数据管理员用户
        /// </summary>
        /// <param name="teamid"></param>
        /// <param name="users"></param>
        /// <returns></returns>
        public bool EditTeamDataAdminInfo(string teamid, string[] users)
        {
            string userIdList="";
            for (int i = 1; i < users.Length; i++)
            {
                userIdList = userIdList + "'"+users[i].ToString() + "',";
            }
            userIdList=userIdList.Substring(0,userIdList.Length-1);
            //将当前课题组用户数据管理员权限去掉
            List<DbCmdInfo> cmdlist = new List<DbCmdInfo>();
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "update tb_team_user set DATAADMIN=0 WHERE TEAM_ID=:p_TEAM_ID",
                delegate()
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "TEAM_ID").ToArray();
                });
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmd.SetParamValues(teamid);
            cmdlist.Add(cmd.DbCmdInfo);
            DbManager.ExecTrans(dbProvider, cmdlist.ToArray());
            //更新当前数据管理员用户
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update tb_team_user set DATAADMIN=1 WHERE USER_ID IN("+userIdList+") and team_id="+teamid);
            DbCmdHelper cmd1 = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd1.DbCmdInfo.CommandType = CommandType.Text;
            return DbManager.ExecTrans(cmd1.DbProvider, cmd1.DbCmdInfo);

            
        }

        /// <summary>
        /// 插入用户到课题组用户表
        /// </summary>
        /// <param name="teamid"></param>
        /// <param name="users"></param>
        /// <returns></returns>
        public bool AddTeamUser(decimal teamid, string userid)
        {
            List<DbCmdInfo> cmdlist = new List<DbCmdInfo>();
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "delete TB_TEAM_USER WHERE TEAM_ID=:p_TEAM_ID",
                delegate()
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "TEAM_ID").ToArray();
                });
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmd.SetParamValues(teamid);
            cmdlist.Add(cmd.DbCmdInfo);
          
             DbCmdHelper cmd_ = new DbCmdHelper(dbProvider, "insert into  TB_TEAM_USER(TEAM_ID,USER_ID,CREATE_TIME,UPD_TIME) values (:p_TEAM_ID,:p_USER_ID,:p_CREATE_TIME,:p_UPD_TIME) ", delegate() { return DbCmdHelper.CreateParameters(dbProvider, "TEAM_ID", "USER_ID", "CREATE_TIME", "UPD_TIME").ToArray(); });
             cmd_.DbCmdInfo.CommandType = CommandType.Text;
             cmd_.SetParamValues(teamid, userid, DateTime.Now, DateTime.Now);
             cmdlist.Add(cmd_.DbCmdInfo);
         

            return DbManager.ExecTrans(dbProvider, cmdlist.ToArray());

            ////bool result = false;
            //DateTime create_time = DateTime.Now;
            //DateTime upd_time = DateTime.Now;
            //StringBuilder strSql = new StringBuilder();
            //strSql.Append("insert into  TB_TEAM_USER(TEAM_ID,USER_ID,CREATE_TIME,UPD_TIME) values (" + teamid + ",'" + userid + "',"+create_time+","+upd_time+")");
            //DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            //cmd.DbCmdInfo.CommandType = CommandType.Text;
            //DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            //if (ds.Rows.Count > 0)
            //    return true;
            //else
            //    return false;
        }
        /// <summary>
        /// 判断是否存在TeamUser
        /// </summary>
        /// <param name="fileid"></param>
        /// <returns></returns>
        public bool isExitTeamUser(decimal teamid,string userid)
        {
            //bool result = false;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT TEAM_ID FROM TB_TEAM_USER where TEAM_ID=" + teamid + " AND USER_ID='" + userid + "'");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds.Rows.Count > 0)
                return true;
            else
                return false;
        }


        /// <summary>
        /// 组织机构数据提取
        /// </summary>
        /// <returns></returns>
        public List<Base_OrganizationInfo> GetOrganizeList()
        {
            StringBuilder strSql = new StringBuilder();
//            strSql.Append(@"SELECT a.*,b.itemname  FROM Base_Organization a
//                            left join base_dictitems b on a.organization_lvl in (select itemvalue from base_dictitems where DICTTYPE_ID=997 )
//                            WHERE a.DeleteMark = 1 ORDER BY a.SortCode ASC");
            strSql.Append(@"SELECT * from   Base_Organization  ORDER BY SortCode ASC");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            List<Base_OrganizationInfo> staffOrgList = DbManager.GetInfoList<Base_OrganizationInfo>(cmd,
                delegate(out Base_OrganizationInfo staffOrg, DataRow row)
                {
                    staffOrg = new Base_OrganizationInfo
                    {
                        ORGANIZATION_ID = ParseHelper.Parse<string>(row["Organization_ID"]),
                        ORGANIZATION_CODE = ParseHelper.Parse<string>(row["ORGANIZATION_CODE"]),
                        ORGANIZATION_NAME = ParseHelper.Parse<string>(row["Organization_Name"]),
                        ORGANIZATION_INNERPHONE = ParseHelper.Parse<string>(row["ORGANIZATION_INNERPHONE"]),
                        ORGANIZATION_OUTERPHONE = ParseHelper.Parse<string>(row["ORGANIZATION_OUTERPHONE"]),
                        ORGANIZATION_MANAGER = ParseHelper.Parse<string>(row["ORGANIZATION_MANAGER"]),
                        ORGANIZATION_ASSISTANTMANAGER = ParseHelper.Parse<string>(row["ORGANIZATION_ASSISTANTMANAGER"]),
                        ORGANIZATION_FAX = ParseHelper.Parse<string>(row["ORGANIZATION_FAX"]),
                        ORGANIZATION_ZIPCODE = ParseHelper.Parse<string>(row["ORGANIZATION_ZIPCODE"]),
                        ORGANIZATION_ADDRESS = ParseHelper.Parse<string>(row["ORGANIZATION_ADDRESS"]),
                        PARENTID = ParseHelper.Parse<string>(row["ParentId"]),
                        ORGANIZATION_REMARK = ParseHelper.Parse<string>(row["ORGANIZATION_REMARK"]),
                        SORTCODE = ParseHelper.Parse<decimal>(row["SORTCODE"]),
                        DELETEMARK = ParseHelper.Parse<decimal>(row["DELETEMARK"]),
                        CREATEDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["CREATEDATE"])),
                        CREATEUSERID = ParseHelper.Parse<string>(row["CREATEUSERID"]),
                        CREATEUSERNAME = ParseHelper.Parse<string>(row["CREATEUSERNAME"]),
                        MODIFYDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["MODIFYDATE"])),
                        MODIFYUSERID = ParseHelper.Parse<string>(row["MODIFYUSERID"]),
                        MODIFYUSERNAME = ParseHelper.Parse<string>(row["MODIFYUSERNAME"]),
                        ORGANIZATION_LVL = ParseHelper.Parse<decimal>(row["ORGANIZATION_LVL"]),
                        //ITEMNAME = ParseHelper.Parse<string>(row["itemname"])
                        
                    };
                });
            for (int i = 0; i < staffOrgList.Count; i++)
            {
                if (staffOrgList[i].ORGANIZATION_LVL == 1)
                    staffOrgList[i].ITEMNAME = "油田";
                else if (staffOrgList[i].ORGANIZATION_LVL ==2)
                    staffOrgList[i].ITEMNAME = "单位";
                else if (staffOrgList[i].ORGANIZATION_LVL == 3)
                    staffOrgList[i].ITEMNAME = "科室";
                else if (staffOrgList[i].ORGANIZATION_LVL ==4)
                    staffOrgList[i].ITEMNAME = "部门";
                else
                    staffOrgList[i].ITEMNAME = " ";
            }
                return staffOrgList;
        }

        /// <summary>
        /// 根据ID取部门信息
        /// </summary>
        /// <param name="ORGANIZATION_ID"></param>
        /// <returns></returns>
        public Base_OrganizationInfo GetOrganizeInfoByID(string ORGANIZATION_ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM Base_Organization WHERE ORGANIZATION_ID=:p_ORGANIZATION_ID");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(), delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, "ORGANIZATION_ID").ToArray();
            });
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmd.SetParamValues(ORGANIZATION_ID);
            Base_OrganizationInfo OrgInfo = DbManager.GetInfo<Base_OrganizationInfo>(cmd,
                delegate(out Base_OrganizationInfo staffOrg, DataRow row)
                {
                    staffOrg = new Base_OrganizationInfo
                    {
                        ORGANIZATION_ID = ParseHelper.Parse<string>(row["Organization_ID"]),
                        ORGANIZATION_CODE = ParseHelper.Parse<string>(row["ORGANIZATION_CODE"]),
                        ORGANIZATION_NAME = ParseHelper.Parse<string>(row["Organization_Name"]),
                        ORGANIZATION_INNERPHONE = ParseHelper.Parse<string>(row["ORGANIZATION_INNERPHONE"]),
                        ORGANIZATION_OUTERPHONE = ParseHelper.Parse<string>(row["ORGANIZATION_OUTERPHONE"]),
                        ORGANIZATION_MANAGER = ParseHelper.Parse<string>(row["ORGANIZATION_MANAGER"]),
                        ORGANIZATION_ASSISTANTMANAGER = ParseHelper.Parse<string>(row["ORGANIZATION_ASSISTANTMANAGER"]),
                        ORGANIZATION_FAX = ParseHelper.Parse<string>(row["ORGANIZATION_FAX"]),
                        ORGANIZATION_ZIPCODE = ParseHelper.Parse<string>(row["ORGANIZATION_ZIPCODE"]),
                        ORGANIZATION_ADDRESS = ParseHelper.Parse<string>(row["ORGANIZATION_ADDRESS"]),
                        PARENTID = ParseHelper.Parse<string>(row["ParentId"]),
                        ORGANIZATION_REMARK = ParseHelper.Parse<string>(row["ORGANIZATION_REMARK"]),
                        SORTCODE = ParseHelper.Parse<decimal>(row["SORTCODE"]),
                        DELETEMARK = ParseHelper.Parse<decimal>(row["DELETEMARK"]),
                        CREATEDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["CREATEDATE"])),
                        CREATEUSERID = ParseHelper.Parse<string>(row["CREATEUSERID"]),
                        CREATEUSERNAME = ParseHelper.Parse<string>(row["CREATEUSERNAME"]),
                        MODIFYDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["MODIFYDATE"])),
                        MODIFYUSERID = ParseHelper.Parse<string>(row["MODIFYUSERID"]),
                        MODIFYUSERNAME = ParseHelper.Parse<string>(row["MODIFYUSERNAME"]),
                        ORGANIZATION_LVL = ParseHelper.Parse<decimal>(row["ORGANIZATION_LVL"])
                    };
                });
            return OrgInfo;
        }

        /// <summary>
        /// 编辑部门
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool EditOrganizationByID(Base_OrganizationCond cond)
        {
            StringBuilder strSql = new StringBuilder();
            //action:0(删除)
            if (cond.action == 0)
            {
                strSql.Append("delete Base_Organization WHERE ORGANIZATION_ID=:p_ORGANIZATION_ID");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "ORGANIZATION_ID").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(cond.ORGANIZATION_ID);
                return DbManager.ExecNonQuery(cmd) > 0;
            }
            else if (cond.action == 1)
            {
                strSql.Append("update BASE_ORGANIZATION set ORGANIZATION_CODE =:p_ORGANIZATION_CODE,ORGANIZATION_NAME =:p_ORGANIZATION_NAME,");
                strSql.Append("ORGANIZATION_INNERPHONE =:p_ORGANIZATION_INNERPHONE,ORGANIZATION_OUTERPHONE =:p_ORGANIZATION_OUTERPHONE,");
                strSql.Append("ORGANIZATION_MANAGER = :p_ORGANIZATION_MANAGER,ORGANIZATION_ASSISTANTMANAGER = :p_ORG_ASSISTANTMANAGER,");
                strSql.Append("ORGANIZATION_FAX =:p_ORGANIZATION_FAX,ORGANIZATION_ZIPCODE =:p_ORGANIZATION_ZIPCODE,");
                strSql.Append("ORGANIZATION_ADDRESS =:p_ORGANIZATION_ADDRESS,PARENTID = :p_PARENTID,ORGANIZATION_REMARK =:p_ORGANIZATION_REMARK,");
                strSql.Append("SORTCODE = :p_SORTCODE,ORGANIZATION_LVL=:p_ORGANIZATION_LVL   WHERE ORGANIZATION_ID=:p_ORGANIZATION_ID");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "ORGANIZATION_CODE", "ORGANIZATION_NAME", "ORGANIZATION_INNERPHONE", "ORGANIZATION_OUTERPHONE", "ORGANIZATION_MANAGER", "ORG_ASSISTANTMANAGER", "ORGANIZATION_FAX", "ORGANIZATION_ZIPCODE", "ORGANIZATION_ADDRESS", "PARENTID", "ORGANIZATION_ID", "ORGANIZATION_REMARK", "SORTCODE", "ORGANIZATION_LVL").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(cond.ORGANIZATION_CODE, cond.ORGANIZATION_NAME, cond.ORGANIZATION_INNERPHONE, cond.ORGANIZATION_OUTERPHONE, cond.ORGANIZATION_MANAGER, cond.ORGANIZATION_ASSISTANTMANAGER, cond.ORGANIZATION_FAX, cond.ORGANIZATION_ZIPCODE, cond.ORGANIZATION_ADDRESS, cond.PARENTID, cond.ORGANIZATION_ID, cond.ORGANIZATION_REMARK, cond.SORTCODE, cond.ORGANIZATION_LVL);
                return DbManager.ExecNonQuery(cmd) > 0;
            }
            else if (cond.action == 2)
            {
                strSql.Append("INSERT INTO BASE_ORGANIZATION (ORGANIZATION_ID, ORGANIZATION_CODE ,ORGANIZATION_NAME ,ORGANIZATION_INNERPHONE ,ORGANIZATION_OUTERPHONE ,ORGANIZATION_MANAGER ,ORGANIZATION_ASSISTANTMANAGER ,ORGANIZATION_FAX ,ORGANIZATION_ZIPCODE ,ORGANIZATION_ADDRESS ,PARENTID ,ORGANIZATION_REMARK ,SORTCODE,ORGANIZATION_LVL  ) VALUES ( ");
                strSql.Append(":p_ORGANIZATION_ID,:p_ORGANIZATION_CODE ,:p_ORGANIZATION_NAME ,:p_ORGANIZATION_INNERPHONE ,:p_ORGANIZATION_OUTERPHONE ,:p_ORGANIZATION_MANAGER ,:p_ORG_ASSISTANTMANAGER ,:p_ORGANIZATION_FAX ,:p_ORGANIZATION_ZIPCODE ,:p_ORGANIZATION_ADDRESS ,:p_PARENTID ,:p_ORGANIZATION_REMARK ,:p_SORTCODE,:p_ORGANIZATION_LVL )");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "ORGANIZATION_ID", "ORGANIZATION_CODE", "ORGANIZATION_NAME", "ORGANIZATION_INNERPHONE", "ORGANIZATION_OUTERPHONE", "ORGANIZATION_MANAGER", "ORG_ASSISTANTMANAGER", "ORGANIZATION_FAX", "ORGANIZATION_ZIPCODE", "ORGANIZATION_ADDRESS", "PARENTID", "ORGANIZATION_REMARK", "SORTCODE", "ORGANIZATION_LVL").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(cond.ORGANIZATION_ID, cond.ORGANIZATION_CODE, cond.ORGANIZATION_NAME, cond.ORGANIZATION_INNERPHONE, cond.ORGANIZATION_OUTERPHONE, cond.ORGANIZATION_MANAGER, cond.ORGANIZATION_ASSISTANTMANAGER, cond.ORGANIZATION_FAX, cond.ORGANIZATION_ZIPCODE, cond.ORGANIZATION_ADDRESS, cond.PARENTID, cond.ORGANIZATION_REMARK, cond.SORTCODE, cond.ORGANIZATION_LVL);
                return DbManager.ExecNonQuery(cmd) > 0;
            }

            return false;
        }
        #endregion

        public List<Base_UserInfo> GetUserInfoPageList(Base_UserCond cond, PageInfo pageInfo, OrderInfo order)
        {
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "sp_getpageuserlist", delegate
             {
                 return DbCmdHelper.CreateParameters(dbProvider, true, "ORGANIZATION_ID", "USER_CODE", "USER_ACCOUNT", "USER_NAME").ToArray();
             });

            cmd.SetParamValues(order, pageInfo, cond.ORGANIZATION_ID, cond.USER_CODE, cond.USER_ACCOUNT, cond.USER_NAME);

            List<Base_UserInfo> userInfoList = DbManager.GetPageInfos(cmd, pageInfo,
                delegate(out Base_UserInfo userInfo, DataRow row)
                {
                    userInfo = new Base_UserInfo
                    {

                        USER_ID = ParseHelper.Parse<string>(row["User_ID"]),
                        USER_CODE = ParseHelper.Parse<string>(row["User_Code"]),
                        USER_ACCOUNT = ParseHelper.Parse<string>(row["User_Account"]),
                        EMAIL = ParseHelper.Parse<string>(row["EMAIL"]),
                        // USER_PWD = ParseHelper.Parse<string>(row["USER_PWD"]),
                        USER_NAME = ParseHelper.Parse<string>(row["User_Name"]),
                        USER_SEX = ParseHelper.Parse<decimal>(row["User_Sex"]),
                        TITLE = ParseHelper.Parse<string>(row["Title"]),
                        USER_REMARK = ParseHelper.Parse<string>(row["User_Remark"]),
                        CREATEDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["CreateDate"])),

                        DELETEMARK = ParseHelper.Parse<decimal>(row["DeleteMark"]),
                        SPACE_SIZE = ParseHelper.Parse<decimal>(row["SPACE_SIZE"]),
                        TELPHONE = ParseHelper.Parse<string>(row["TELPHONE"]),
                        SPACE_CURE_USE = ParseHelper.Parse<decimal>(row["SPACE_CURE_USE"]),
                        SPACE_STATUS = ParseHelper.Parse<decimal>(row["SPACE_STATUS"]),
                        ORGANIZATION_NAME = ParseHelper.Parse<string>(row["ORGANIZATION_NAME"]),
                        ROLES_NAMELIST = ParseHelper.Parse<string>(row["ROLES_NAME"])
                    };
                });
            return userInfoList;
        }

        /// 根据用户名密码取用户信息
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public Base_UserInfo GetUserByNamePassword(Base_LoginCond cond)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("Select User_ID,User_Code,User_Account,User_Pwd,User_Name,DeleteMark,USER_LANG from Base_UserInfo where ");
            strSql.Append("User_Account= :p_User_Account ");
            strSql.Append("and User_Pwd= :p_User_Pwd ");
            strSql.Append("and DeleteMark!=0");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(), delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, "User_Account", "User_Pwd").ToArray();
            });
            cmd.SetParamValues(cond.name, cond.pwd.ToUpper());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            Base_UserInfo userInfo = DbManager.GetInfo(cmd,
                delegate(out Base_UserInfo u, DataRow row)
                {
                    u = new Base_UserInfo
                    {
                        USER_ID = ParseHelper.Parse<string>(row["USER_ID"]),
                        USER_NAME = ParseHelper.Parse<string>(row["USER_NAME"]),
                        USER_ACCOUNT = ParseHelper.Parse<string>(row["USER_ACCOUNT"]),
                        DELETEMARK = ParseHelper.Parse<decimal>(row["DELETEMARK"]),
                        USER_CODE = ParseHelper.Parse<string>(row["USER_CODE"]),
                        USER_LANG = ParseHelper.Parse<decimal>(row["USER_LANG"]),
                        OEMSession = ParseHelper.Parse<string>(row["USER_ID"]) + "_" + DateTime.Now.ToString("HHmmssffff")
                    };
                });
            return userInfo;
        }

        /// 根据工号取用户信息
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public Base_UserInfo GetUserByID(string ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select a.*, (a.space_size-a.space_cure_use) as PACE_SURPLUS_SIZE,c.organization_name from Base_UserInfo a
                            left join base_stafforganize b on a.user_id = b.user_id
                            left join Base_Organization c on b.organization_id = c.organization_id
                             where a.USER_ID=:p_ID ");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(), delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, "ID").ToArray();
            });
            cmd.SetParamValues(ID);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            Base_UserInfo userInfo = DbManager.GetInfo(cmd,
                delegate(out Base_UserInfo u, DataRow row)
                {
                    u = new Base_UserInfo
                    {
                        USER_CODE = ParseHelper.Parse<string>(row["USER_CODE"]),
                        USER_ID = ParseHelper.Parse<string>(row["USER_ID"]),
                        USER_NAME = ParseHelper.Parse<string>(row["USER_NAME"]),
                        USER_ACCOUNT = ParseHelper.Parse<string>(row["USER_ACCOUNT"]),
                        DELETEMARK = ParseHelper.Parse<decimal>(row["DELETEMARK"]),
                        USER_PWD = ParseHelper.Parse<string>(row["User_Pwd"]),
                        USER_REMARK = ParseHelper.Parse<string>(row["USER_REMARK"]),
                        TITLE = ParseHelper.Parse<string>(row["TITLE"]),
                        EMAIL = ParseHelper.Parse<string>(row["EMAIL"]),
                        CREATEDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["CREATEDATE"])),
                        USER_SEX = ParseHelper.Parse<decimal>(row["USER_SEX"]),
                        TELPHONE = ParseHelper.Parse<string>(row["TELPHONE"]),
                        SPACE_STATUS = ParseHelper.Parse<decimal>(row["SPACE_STATUS"]),
                        SPACE_SIZE = ParseHelper.Parse<decimal>(row["SPACE_SIZE"]),
                        SPACE_CURE_USE = ParseHelper.Parse<decimal>(row["SPACE_CURE_USE"]),
                        INTEGRAL = ParseHelper.Parse<decimal>(row["INTEGRAL"]),
                        USER_LANG = ParseHelper.Parse<decimal>(row["USER_LANG"]),
                        PACE_SURPLUS_SIZE = ParseHelper.Parse<string>(row["PACE_SURPLUS_SIZE"])
                    };
                });
            return userInfo;
        }

        /// <summary>
        /// 用户编辑 
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool EditUserInfo(Base_UserInfoCond cond)
        {
            StringBuilder strSql = new StringBuilder();
            //action:0(删除)
            if (cond.action == 0)
            {
                List<DbCmdInfo> cmdlist = new List<DbCmdInfo>();
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, "delete BASE_USERINFO WHERE User_Id=:p_User_Id",
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "User_Id").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(cond.USER_ID);
                cmdlist.Add(cmd.DbCmdInfo);

                DbCmdHelper cmd2 = new DbCmdHelper(dbProvider, "delete BASE_STAFFORGANIZE  where User_ID=:p_USER_ID", delegate() { return DbCmdHelper.CreateParameters(dbProvider, "USER_ID").ToArray(); });
                cmd2.DbCmdInfo.CommandType = CommandType.Text;
                cmd2.SetParamValues(cond.USER_ID);
                cmdlist.Add(cmd2.DbCmdInfo);

                //删除用户角色
                DbCmdHelper cmd3 = new DbCmdHelper(dbProvider, "delete BASE_USERROLE  where User_ID=:p_USER_ID", delegate() { return DbCmdHelper.CreateParameters(dbProvider, "USER_ID").ToArray(); });
                cmd3.DbCmdInfo.CommandType = CommandType.Text;
                cmd3.SetParamValues(cond.USER_ID);
                cmdlist.Add(cmd3.DbCmdInfo);
                return DbManager.ExecTrans(dbProvider, cmdlist.ToArray());
            }
            else if (cond.action == 1)//编辑
            {
                List<DbCmdInfo> cmdlist = new List<DbCmdInfo>();
                strSql.Append("update BASE_USERINFO set USER_CODE = :p_USER_CODE,USER_ACCOUNT = :p_USER_ACCOUNT,USER_NAME = :p_USER_NAME,");
                if (!string.IsNullOrEmpty(cond.USER_PWD))
                {
                    strSql.Append("USER_PWD = :p_USER_PWD,");
                }
                strSql.Append("USER_SEX = :p_USER_SEX,TITLE = :p_TITLE,EMAIL =:p_EMAIL,USER_REMARK = :p_USER_REMARK,TELPHONE = :p_TELPHONE, SPACE_STATUS = :p_SPACE_STATUS,SPACE_SIZE = :p_SPACE_SIZE,SPACE_CURE_USE = :p_SPACE_CURE_USE,INTEGRAL=:p_INTEGRAL  where USER_ID=:p_USER_ID");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        if (!string.IsNullOrEmpty(cond.USER_PWD))
                        {
                            return DbCmdHelper.CreateParameters(dbProvider, "USER_CODE", "USER_ACCOUNT", "USER_NAME", "USER_PWD", "USER_SEX", "TITLE", "EMAIL", "USER_REMARK", "TELPHONE", "SPACE_STATUS", "SPACE_SIZE", "SPACE_CURE_USE", "INTEGRAL", "USER_ID").ToArray();
                        }
                        else
                            return DbCmdHelper.CreateParameters(dbProvider, "USER_CODE", "USER_ACCOUNT", "USER_NAME", "USER_SEX", "TITLE", "EMAIL", "USER_REMARK", "TELPHONE", "SPACE_STATUS", "SPACE_SIZE", "SPACE_CURE_USE", "INTEGRAL", "USER_ID").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                if (!string.IsNullOrEmpty(cond.USER_PWD))
                    cmd.SetParamValues(cond.USER_CODE, cond.USER_ACCOUNT, cond.USER_NAME, cond.USER_PWD.ToUpper(), cond.USER_SEX, cond.TITLE, cond.EMAIL, cond.USER_REMARK,cond.TELPHONE,cond.SPACE_STATUS,cond.SPACE_SIZE,cond.SPACE_CURE_USE,cond.INTEGRAL, cond.USER_ID);
                else
                    cmd.SetParamValues(cond.USER_CODE, cond.USER_ACCOUNT, cond.USER_NAME, cond.USER_SEX, cond.TITLE, cond.EMAIL, cond.USER_REMARK, cond.TELPHONE, cond.SPACE_STATUS, cond.SPACE_SIZE, cond.SPACE_CURE_USE, cond.INTEGRAL, cond.USER_ID);
                cmdlist.Add(cmd.DbCmdInfo);
                DbCmdHelper cmd2 = new DbCmdHelper(dbProvider, "delete BASE_STAFFORGANIZE  where User_ID=:p_USER_ID", delegate() { return DbCmdHelper.CreateParameters(dbProvider, "USER_ID").ToArray(); });
                cmd2.DbCmdInfo.CommandType = CommandType.Text;
                cmd2.SetParamValues(cond.USER_ID);
                cmdlist.Add(cmd2.DbCmdInfo);

                DbCmdHelper cmdORG;
                if (cond.orgID.Count > 0)
                {
                    foreach (Base_UserOrgInfo _orgID in cond.orgID)
                    {
                        string stafforgID = Guid.NewGuid().ToString();
                        cmdORG = new DbCmdHelper(dbProvider, "INSERT INTO BASE_STAFFORGANIZE ( STAFFORGANIZE_ID,ORGANIZATION_ID,USER_ID) VALUES (:p_STAFFORGANIZE_ID,:p_ORGANIZATION_ID,:p_USER_ID)", delegate() { return DbCmdHelper.CreateParameters(dbProvider, "STAFFORGANIZE_ID", "ORGANIZATION_ID", "USER_ID").ToArray(); });
                        cmdORG.DbCmdInfo.CommandType = CommandType.Text;
                        cmdORG.SetParamValues(stafforgID, _orgID.OrgID, cond.USER_ID);
                        cmdlist.Add(cmdORG.DbCmdInfo);
                    }
                }

                //删除用户角色
                DbCmdHelper cmd3 = new DbCmdHelper(dbProvider, "delete BASE_USERROLE  where User_ID=:p_USER_ID", delegate() { return DbCmdHelper.CreateParameters(dbProvider, "USER_ID").ToArray(); });
                cmd3.DbCmdInfo.CommandType = CommandType.Text;
                cmd3.SetParamValues(cond.USER_ID);
                cmdlist.Add(cmd3.DbCmdInfo);

                DbCmdHelper cmdORLE;//角色
                if (cond.RoleList.Count > 0)
                {
                    foreach (string role in cond.RoleList)
                    {
                        string USERROLE_ID = Guid.NewGuid().ToString();
                        cmdORLE = new DbCmdHelper(dbProvider, "INSERT INTO BASE_USERROLE ( USERROLE_ID ,USER_ID ,ROLES_ID ) VALUES ('" + USERROLE_ID + "',:p_USER_ID,:p_ROLES_ID)", delegate() { return DbCmdHelper.CreateParameters(dbProvider, "USER_ID", "ROLES_ID").ToArray(); });
                        cmdORLE.DbCmdInfo.CommandType = CommandType.Text;
                        cmdORLE.SetParamValues(cond.USER_ID, role);
                        cmdlist.Add(cmdORLE.DbCmdInfo);
                    }
                }
                return DbManager.ExecTrans(dbProvider, cmdlist.ToArray());
            }
            else if (cond.action == 2)//新增
            {
                List<DbCmdInfo> cmdlist = new List<DbCmdInfo>();
                strSql.Append("INSERT INTO BASE_USERINFO ( USER_ID ,USER_CODE ,USER_ACCOUNT ,USER_PWD ,USER_NAME ,USER_SEX ,TITLE ,EMAIL ,USER_REMARK ,TELPHONE, SPACE_STATUS, SPACE_SIZE, SPACE_CURE_USE, INTEGRAL) VALUES (");
                strSql.Append(":p_USER_ID ,:p_USER_CODE ,:p_USER_ACCOUNT ,:p_USER_PWD ,:p_USER_NAME ,:p_USER_SEX ,:p_TITLE ,:p_EMAIL ,:p_USER_REMARK,:p_TELPHONE,:p_SPACE_STATUS,:p_SPACE_SIZE,:p_SPACE_CURE_USE,:p_INTEGRAL)");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "USER_ID", "USER_CODE", "USER_ACCOUNT", "USER_PWD", "USER_NAME", "USER_SEX", "TITLE", "EMAIL", "USER_REMARK", "TELPHONE", "SPACE_STATUS", "SPACE_SIZE", "SPACE_CURE_USE", "INTEGRAL").ToArray();
                    });
                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(cond.USER_ID, cond.USER_CODE, cond.USER_ACCOUNT, cond.USER_PWD.ToUpper(), cond.USER_NAME, cond.USER_SEX, cond.TITLE, cond.EMAIL,cond.USER_REMARK,cond.TELPHONE, cond.SPACE_STATUS, cond.SPACE_SIZE, cond.SPACE_CURE_USE, cond.INTEGRAL);
                cmdlist.Add(cmd.DbCmdInfo);
                DbCmdHelper cmdORG;//部门
                if (cond.orgID.Count > 0)
                {
                    foreach (Base_UserOrgInfo _orgID in cond.orgID)
                    {
                        string stafforgID = Guid.NewGuid().ToString();
                        cmdORG = new DbCmdHelper(dbProvider, "INSERT INTO BASE_STAFFORGANIZE ( STAFFORGANIZE_ID ,ORGANIZATION_ID ,USER_ID) VALUES ('" + stafforgID + "',:p_ORGANIZATION_ID,:p_USER_ID)", delegate() { return DbCmdHelper.CreateParameters(dbProvider, "ORGANIZATION_ID", "USER_ID").ToArray(); });
                        cmdORG.DbCmdInfo.CommandType = CommandType.Text;
                        cmdORG.SetParamValues(_orgID.OrgID, cond.USER_ID);
                        cmdlist.Add(cmdORG.DbCmdInfo);
                    }
                }
                DbCmdHelper cmdORLE;//角色
                if (cond.RoleList.Count > 0)
                {
                    foreach (string role in cond.RoleList)
                    {
                        string USERROLE_ID = Guid.NewGuid().ToString();
                        cmdORLE = new DbCmdHelper(dbProvider, "INSERT INTO BASE_USERROLE ( USERROLE_ID ,USER_ID ,ROLES_ID ) VALUES ('" + USERROLE_ID + "',:p_USER_ID,:p_ROLES_ID)", delegate() { return DbCmdHelper.CreateParameters(dbProvider, "USER_ID", "ROLES_ID").ToArray(); });
                        cmdORLE.DbCmdInfo.CommandType = CommandType.Text;
                        cmdORLE.SetParamValues(cond.USER_ID, role);
                        cmdlist.Add(cmdORLE.DbCmdInfo);
                    }
                }
                return DbManager.ExecTrans(dbProvider, cmdlist.ToArray());
            }

            return false;
        }
        public List<Base_UserInfo> QueryUserInfo(Base_UserInfo cond)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * from Base_UserInfo where DeleteMark !=0");
            //strSql.Append(SqlWhere);

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            List<Base_UserInfo> userList = DbManager.GetInfoList<Base_UserInfo>(cmd,
                delegate(out Base_UserInfo user, DataRow row)
                {
                    user = new Base_UserInfo
                    {
                        USER_ID = ParseHelper.Parse<string>(row["USER_ID"]),
                        USER_CODE = ParseHelper.Parse<string>(row["USER_CODE"]),
                        USER_NAME = ParseHelper.Parse<string>(row["USER_NAME"]),
                        USER_ACCOUNT = ParseHelper.Parse<string>(row["USER_ACCOUNT"]),
                        USER_SEX = ParseHelper.Parse<decimal>(row["USER_SEX"]),
                        TITLE = ParseHelper.Parse<string>(row["TITLE"]),
                        DELETEMARK = ParseHelper.Parse<decimal>(row["DELETEMARK"]),
                        USER_REMARK = ParseHelper.Parse<string>(row["USER_REMARK"]),
                        CREATEDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["CREATEDATE"]))
                    };
                });
            return userList;
        }


        public List<Base_UserRightInfo> GetUserRight(string User_ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT Menu_Id FROM Base_UserRight WHERE User_ID = :p_User_ID");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(), delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, "User_ID").ToArray();
            });
            cmd.SetParamValues(User_ID);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            List<Base_UserRightInfo> userRightList = DbManager.GetInfoList<Base_UserRightInfo>(cmd,
                delegate(out Base_UserRightInfo u, DataRow row)
                {
                    u = new Base_UserRightInfo
                    {
                        USER_ID = User_ID,
                        MENU_ID = ParseHelper.Parse<string>(row["MENU_ID"])
                    };
                });
            return userRightList;
        }


        /// <summary>
        /// 取角色权限
        /// </summary>
        /// <param name="ROLES_ID"></param>
        /// <returns></returns>
        public List<Base_RoleRightInfo> QueryRoleRightsByID(string ROLES_ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select MENU_ID  from BASE_ROLERIGHT where ROLES_ID=:p_ROLES_ID");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(), delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, "ROLES_ID").ToArray();
            });
            cmd.SetParamValues(ROLES_ID);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            List<Base_RoleRightInfo> userRightList = DbManager.GetInfoList<Base_RoleRightInfo>(cmd,
                delegate(out Base_RoleRightInfo u, DataRow row)
                {
                    u = new Base_RoleRightInfo
                    {
                        ROLES_ID = ROLES_ID,
                        MENU_ID = ParseHelper.Parse<string>(row["MENU_ID"])
                    };
                });
            return userRightList;
        }


        /// <summary>
        /// 编辑角色权限
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool EditRoleRights(Base_RoleRightsCond cond)
        {
            List<DbCmdInfo> cmdlist = new List<DbCmdInfo>();
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "delete BASE_ROLERIGHT where ROLES_ID=:p_ROLES_ID", delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, "ROLES_ID").ToArray();
            });
            cmd.SetParamValues(cond.ROLES_ID);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmdlist.Add(cmd.DbCmdInfo);

            if (cond.RoleRightList.Count > 0)
            {
                DbCmdHelper cmdORLE;
                foreach (string roleright in cond.RoleRightList)
                {
                    string roleright_ID = Guid.NewGuid().ToString();
                    cmdORLE = new DbCmdHelper(dbProvider, "INSERT INTO BASE_ROLERIGHT (ROLERIGHT_ID,ROLES_ID,MENU_ID) values (:p_ROLERIGHT_ID,:p_ROLES_ID,:p_MENU_ID)",
                        delegate() { return DbCmdHelper.CreateParameters(dbProvider, "ROLERIGHT_ID", "ROLES_ID", "MENU_ID").ToArray(); });
                    cmdORLE.DbCmdInfo.CommandType = CommandType.Text;
                    cmdORLE.SetParamValues(roleright_ID, cond.ROLES_ID, roleright);
                    cmdlist.Add(cmdORLE.DbCmdInfo);
                }
            }
            return DbManager.ExecTrans(dbProvider, cmdlist.ToArray());
        }
        /// <summary>
        /// 编辑角色操作权限
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool EditRoleOpraRights(Base_FileRoleRightCond cond)
        {
            //如果已经存在则删除
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete BASE_FILEROLERIGHT where ROLES_ID='" + cond.ROLES_ID + "'");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);

            bool result = true;
            StringBuilder strSql1 = new StringBuilder();
            strSql1.Append("insert into BASE_FILEROLERIGHT(ROLES_ID , SEE_SECR ,DOWN_PDF_SECR  ,DOWN_SOURCE_SECR) values('" + cond.ROLES_ID + "'," + cond.SEE_SECR + "," + cond.DOWN_PDF_SECR + "," + cond.DOWN_SOURCE_SECR + ")");
            DbCmdHelper cmd1 = new DbCmdHelper(dbProvider, strSql1.ToString());

            cmd1.DbCmdInfo.CommandType = CommandType.Text;
            int back1 = DbManager.ExecNonQuery(cmd1);
            if (back1 == 0)
                result = false;

            return result;
        
        }
        /// <summary>
        /// 获取当前角色文档操作权限
        /// </summary>
        /// <param name="ROLES_ID"></param>
        /// <returns></returns>
        public Base_RoleOpraRightsCond GetRoleOpraRight(string ROLE_ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT * FROM BASE_ROLEOPRARIGHT WHERE ROLE_ID = '" + ROLE_ID+"'");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            Base_RoleOpraRightsCond Obj = DbManager.GetInfo(cmd,
                delegate(out Base_RoleOpraRightsCond u, DataRow row)
                {
                    u = new Base_RoleOpraRightsCond
                    {
                        SEE_SECR = ParseHelper.Parse<decimal>(row["SEE_SECR"]),
                        DOWN_PDF_SECR = ParseHelper.Parse<decimal>(row["DOWN_PDF_SECR"]),
                        DOWN_SOURCE_SECR = ParseHelper.Parse<decimal>(row["DOWN_SOURCE_SECR"])
                        
                    };
                });
            return Obj;
        }

        /// <summary>
        /// 取角色目标树
        /// </summary>
        /// <param name="ROLES_ID"></param>
        /// <returns></returns>
        public List<Base_RoleRightInfo> QueryRoleTreeByID(string ROLES_ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select TREE_ID,FILELEVEL  from BASE_ROLETREE where ROLES_ID=:p_ROLES_ID");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(), delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, "ROLES_ID").ToArray();
            });
            cmd.SetParamValues(ROLES_ID);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            List<Base_RoleRightInfo> userRightList = DbManager.GetInfoList<Base_RoleRightInfo>(cmd,
                delegate(out Base_RoleRightInfo u, DataRow row)
                {
                    u = new Base_RoleRightInfo
                    {
                        ROLES_ID = ROLES_ID,
                        MENU_ID = ParseHelper.Parse<string>(row["TREE_ID"]),
                        RightsLevel = ParseHelper.Parse<int>(row["FILELEVEL"])
                    };
                });
            return userRightList;
        }

        /// <summary>
        /// 编辑角色权限
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool EditRoleTree(TargetFileRightCond cond)
        {
            List<DbCmdInfo> cmdlist = new List<DbCmdInfo>();
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "delete BASE_ROLETREE where ROLES_ID=:p_ROLES_ID", delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, "ROLES_ID").ToArray();
            });
            cmd.SetParamValues(cond.RoleID);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmdlist.Add(cmd.DbCmdInfo);

            if (cond.FileRightsList.Count > 0)
            {
                DbCmdHelper cmdORLE;
                foreach (FileRightsInfo targetright in cond.FileRightsList)
                {
                    string roleright_ID = Guid.NewGuid().ToString();
                    cmdORLE = new DbCmdHelper(dbProvider, "INSERT INTO BASE_ROLETREE ( ROLERIGHT_ID ,ROLES_ID ,TREE_ID,FILELEVEL ) values (:p_ROLERIGHT_ID,:p_ROLES_ID,:p_MENU_ID,:p_FILELEVEL)", delegate() { return DbCmdHelper.CreateParameters(dbProvider, "ROLERIGHT_ID", "ROLES_ID", "MENU_ID", "FILELEVEL").ToArray(); });
                    cmdORLE.DbCmdInfo.CommandType = CommandType.Text;
                    cmdORLE.SetParamValues(roleright_ID, cond.RoleID, targetright.ObjID, targetright.RightsLevel);
                    cmdlist.Add(cmdORLE.DbCmdInfo);
                }
            }
            return DbManager.ExecTrans(dbProvider, cmdlist.ToArray());
        }

        public List<Base_UserInfoUserGroupInfo> GetUserGroup(string User_ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT UserGroup_ID FROM Base_UserInfoUserGroup WHERE User_ID = :p_User_ID");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(), delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, "User_ID").ToArray();
            });
            cmd.SetParamValues(User_ID);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            List<Base_UserInfoUserGroupInfo> userGroupList = DbManager.GetInfoList<Base_UserInfoUserGroupInfo>(cmd,
                delegate(out Base_UserInfoUserGroupInfo u, DataRow row)
                {
                    u = new Base_UserInfoUserGroupInfo
                    {
                        USER_ID = ParseHelper.Parse<string>(row["USER_ID"]),
                        USERGROUP_ID = ParseHelper.Parse<string>(row["USERGROUP_ID"])
                    };
                });
            return userGroupList;
        }

        public List<Base_UserRoleInfo> GetUserRole(string User_ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT Roles_ID FROM Base_UserRole WHERE User_ID = :p_User_ID");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(), delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, "User_ID").ToArray();
            });
            cmd.SetParamValues(User_ID);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            List<Base_UserRoleInfo> userRolesList = DbManager.GetInfoList<Base_UserRoleInfo>(cmd,
                delegate(out Base_UserRoleInfo u, DataRow row)
                {
                    u = new Base_UserRoleInfo
                    {
                        USER_ID = User_ID,
                        ROLES_ID = ParseHelper.Parse<string>(row["ROLES_ID"])
                    };
                });
            return userRolesList;
        }

        public List<Base_StaffOrganizeInfo> GetStaffOrganize(string User_ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT Organization_ID FROM Base_StaffOrganize WHERE User_ID = :p_User_ID");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(), delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, "User_ID").ToArray();
            });
            cmd.SetParamValues(User_ID);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            List<Base_StaffOrganizeInfo> userOrganizationList = DbManager.GetInfoList<Base_StaffOrganizeInfo>(cmd,
                delegate(out Base_StaffOrganizeInfo u, DataRow row)
                {
                    u = new Base_StaffOrganizeInfo
                    {
                        USER_ID = User_ID,
                        ORGANIZATION_ID = ParseHelper.Parse<string>(row["ORGANIZATION_ID"])
                    };
                });
            return userOrganizationList;
        }

        public void AddSysLoginLog(Base_SysLoginLogInfo cond)
        {

            string sql = @"insert into Base_SysLoginlog(SYS_LOGINLOG_ID, User_Account, SYS_LOGINLOG_IP, OWNER_address, SYS_LOGINLOG_STATUS)
                           values(:p_SYS_LOGINLOG_ID, :p_User_Account, :p_SYS_LOGINLOG_IP, :p_OWNER_address, :p_SYS_LOGINLOG_STATUS)";

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, sql,
                //参数生成
                delegate()
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "SYS_LOGINLOG_ID", "User_Account",
                        "SYS_LOGINLOG_IP", "OWNER_address", "SYS_LOGINLOG_STATUS").ToArray();
                });

            //参数设值
            cmd.SetParamValues(cond.SYS_LOGINLOG_ID, cond.USER_ACCOUNT, cond.SYS_LOGINLOG_IP,
                cond.OWNER_ADDRESS, cond.SYS_LOGINLOG_STATUS);
            cmd.DbCmdInfo.CommandType = CommandType.Text;

            DbManager.ExecNonQuery(cmd);
        }

        public List<Base_SysLoginLogInfo> QuerySysLoginLog(Base_SysLoginLogInfo cond, PageInfo pageInfo, OrderInfo order)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * from Base_SysLoginlog where 1=1");
            //strSql.Append(SqlWhere);

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            List<Base_SysLoginLogInfo> logList = DbManager.GetPageInfos<Base_SysLoginLogInfo>(cmd, pageInfo,
                delegate(out Base_SysLoginLogInfo user, DataRow row)
                {
                    user = new Base_SysLoginLogInfo
                    {
                        SYS_LOGINLOG_ID = ParseHelper.Parse<string>(row["SYS_LOGINLOG_ID"]),
                        SYS_LOGINLOG_IP = ParseHelper.Parse<string>(row["SYS_LOGINLOG_IP"]),
                        SYS_LOGINLOG_TIME = ParseHelper.Parse<DateTime?>(row["SYS_LOGINLOG_TIME"]),
                        USER_ACCOUNT = ParseHelper.Parse<string>(row["USER_ACCOUNT"]),
                        SYS_LOGINLOG_STATUS = ParseHelper.Parse<decimal>(row["SYS_LOGINLOG_STATUS"]),
                        OWNER_ADDRESS = ParseHelper.Parse<string>(row["OWNER_ADDRESS"])
                    };
                });
            return logList;
        }

        public List<Base_SysLoginLogInfo> GetLoginLogInfo(Base_UserInfo userInfo, PageInfo pageInfo, OrderInfo order)
        {
            //取前2行
            DateTime now = DateTime.Now;
            DateTime d = new DateTime(now.Year, now.Month, 1);
            DateTime d2 = d.AddMonths(1).AddDays(-1.0);
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSqlCount = new StringBuilder();
            strSql.Append("Select SYS_LOGINLOG_IP,Sys_LoginLog_Time from Base_SysLoginlog where User_Account = :p_User_Account");
            strSql.Append(" and Sys_LoginLog_Time >= :p_BeginBuilTime");
            strSql.Append(" and Sys_LoginLog_Time <= :p_endBuilTime ORDER BY Sys_LoginLog_Time DESC ");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                delegate
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "User_Account", "BeginBuilTime", "endBuilTime").ToArray();
                });

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmd.SetParamValues(userInfo.USER_ACCOUNT, d, d2);
            List<Base_SysLoginLogInfo> logList = DbManager.GetPageInfos<Base_SysLoginLogInfo>(cmd, pageInfo,
                delegate(out Base_SysLoginLogInfo user, DataRow row)
                {
                    user = new Base_SysLoginLogInfo
                    {
                        SYS_LOGINLOG_ID = ParseHelper.Parse<string>(row["SYS_LOGINLOG_ID"]),
                        SYS_LOGINLOG_IP = ParseHelper.Parse<string>(row["SYS_LOGINLOG_IP"]),
                        SYS_LOGINLOG_TIME = ParseHelper.Parse<DateTime?>(row["SYS_LOGINLOG_TIME"]),
                        USER_ACCOUNT = ParseHelper.Parse<string>(row["USER_ACCOUNT"]),
                        SYS_LOGINLOG_STATUS = ParseHelper.Parse<decimal>(row["SYS_LOGINLOG_STATUS"]),
                        OWNER_ADDRESS = ParseHelper.Parse<string>(row["OWNER_ADDRESS"])
                    };
                });
            return logList;
        }

        public List<Base_UserGroupInfo> GetUserGroupList()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * from Base_UserGroup WHERE DeleteMark = 1 ORDER BY SortCode ASC");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            List<Base_UserGroupInfo> userGroupList = DbManager.GetInfoList<Base_UserGroupInfo>(cmd,
                delegate(out Base_UserGroupInfo user, DataRow row)
                {
                    user = new Base_UserGroupInfo
                    {
                        USERGROUP_ID = ParseHelper.Parse<string>(row["USERGROUP_ID"]),
                        PARENTID = ParseHelper.Parse<string>(row["PARENTID"]),
                        USERGROUP_CODE = ParseHelper.Parse<string>(row["USERGROUP_CODE"]),
                        USERGROUP_NAME = ParseHelper.Parse<string>(row["USERGROUP_NAME"]),
                        USERGROUP_REMARK = ParseHelper.Parse<string>(row["USERGROUP_REMARK"]),
                        ALLOWEDIT = ParseHelper.Parse<decimal>(row["ALLOWEDIT"]),
                        ALLOWDELETE = ParseHelper.Parse<decimal>(row["ALLOWDELETE"]),
                        SORTCODE = ParseHelper.Parse<decimal>(row["SORTCODE"]),
                        DELETEMARK = ParseHelper.Parse<decimal>(row["DELETEMARK"]),
                        CREATEDATE = ParseHelper.Parse<DateTime>(row["CREATEDATE"]),
                        CREATEUSERID = ParseHelper.Parse<string>(row["CREATEUSERID"]),
                        CREATEUSERNAME = ParseHelper.Parse<string>(row["CREATEUSERNAME"]),
                        MODIFYDATE = ParseHelper.Parse<DateTime>(row["MODIFYDATE"]),
                        MODIFYUSERID = ParseHelper.Parse<string>(row["MODIFYUSERID"]),
                        MODIFYUSERNAME = ParseHelper.Parse<string>(row["MODIFYUSERNAME"])
                    };
                });
            return userGroupList;
        }

        public List<Base_UserGroupInfo> InitUserGroupParentId()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT UserGroup_ID,
                                   UserGroup_Name ||' - ' || CASE ParentId
                                     WHEN '0' THEN
                                      '父节'
                                     ELSE
                                      '子节'
                                   END AS UserGroup_Name 
                              FROM Base_UserGroup
                             WHERE DeleteMark = 1
                             ORDER BY SortCode ASC");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            List<Base_UserGroupInfo> userGroupList = DbManager.GetInfoList<Base_UserGroupInfo>(cmd,
                delegate(out Base_UserGroupInfo user, DataRow row)
                {
                    user = new Base_UserGroupInfo
                    {
                        USERGROUP_ID = ParseHelper.Parse<string>(row["USERGROUP_ID"]),
                        USERGROUP_NAME = ParseHelper.Parse<string>(row["USERGROUP_NAME"])
                    };
                });
            return userGroupList;
        }

        public List<Base_UserInfo> Load_UserInfoUserGroupList(Base_UserGroupInfo userGroupInfo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT UserInfoUserGroup_ID,
                                   U.User_Name || '|' || U.User_Code AS User_Name,
                                   U.User_Account,
                                   U.User_Sex,
                                   U.Title,
                                   U.DeleteMark,
                                   U.User_Remark 
                              FROM Base_UserInfo U
                             RIGHT JOIN Base_UserInfoUserGroup G
                                ON G.User_ID = U.User_ID WHERE G.USER_GROUPID = :p_USER_GROUPID");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                delegate
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "USER_GROUPID").ToArray();
                });

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmd.SetParamValues(userGroupInfo.USERGROUP_ID);
            List<Base_UserInfo> userGroupList = DbManager.GetInfoList<Base_UserInfo>(cmd,
                delegate(out Base_UserInfo user, DataRow row)
                {
                    user = new Base_UserInfo
                    {
                        USER_REMARK = ParseHelper.Parse<string>(row["UserInfoUserGroup_ID"]),
                        USER_NAME = ParseHelper.Parse<string>(row["USER_NAME"]),
                        USER_ACCOUNT = ParseHelper.Parse<string>(row["USER_ACCOUNT"]),
                        USER_SEX = ParseHelper.Parse<decimal>(row["USER_SEX"]),
                        TITLE = ParseHelper.Parse<string>(row["TITLE"]),
                        DELETEMARK = ParseHelper.Parse<decimal>(row["DELETEMARK"])
                    };
                });
            return userGroupList;
        }

        //public DataTable InitUserGroupRight(string UserGroup_ID)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("SELECT Menu_Id FROM Base_UserGroupRight WHERE UserGroup_ID = @UserGroup_ID");
        //    SqlParam[] para = new SqlParam[]
        //    {
        //        new SqlParam("@UserGroup_ID", UserGroup_ID)
        //    };
        //    return DataFactory.SqlDataBase().GetDataTableBySQL(strSql, para);
        //}

        //public bool AddUserGroupMenber(string[] User_ID, string UserGroup_ID)
        //{
        //    bool result;
        //    try
        //    {
        //        StringBuilder[] sqls = new StringBuilder[User_ID.Length];
        //        object[] objs = new object[User_ID.Length];
        //        int index = 0;
        //        for (int i = 0; i < User_ID.Length; i++)
        //        {
        //            string item = User_ID[i];
        //            if (item.Length > 0)
        //            {
        //                StringBuilder sbadd = new StringBuilder();
        //                sbadd.Append("Insert into Base_UserInfoUserGroup(");
        //                sbadd.Append("UserInfoUserGroup_ID,User_ID,UserGroup_ID,CreateUserId,CreateUserName");
        //                sbadd.Append(")Values(");
        //                sbadd.Append("@UserInfoUserGroup_ID,@User_ID,@UserGroup_ID,@CreateUserId,@CreateUserName)");
        //                SqlParam[] parmAdd = new SqlParam[]
        //                {
        //                    new SqlParam("@UserInfoUserGroup_ID", CommonHelper.GetGuid),
        //                    new SqlParam("@User_ID", item),
        //                    new SqlParam("@UserGroup_ID", UserGroup_ID),
        //                    new SqlParam("@CreateUserId", RequestSession.GetSessionUser().UserId),
        //                    new SqlParam("@CreateUserName", RequestSession.GetSessionUser().UserName)
        //                };
        //                sqls[index] = sbadd;
        //                objs[index] = parmAdd;
        //                index++;
        //            }
        //        }
        //        result = (DataFactory.SqlDataBase().BatchExecuteBySql(sqls, objs) >= 0);
        //    }
        //    catch
        //    {
        //        result = false;
        //    }
        //    return result;
        //}

        //public bool Add_UserGroupAllotAuthority(string[] pkVal, string UserGroup_ID)
        //{
        //    bool result;
        //    try
        //    {
        //        StringBuilder[] sqls = new StringBuilder[pkVal.Length + 1];
        //        object[] objs = new object[pkVal.Length + 1];
        //        StringBuilder sbDelete = new StringBuilder();
        //        sbDelete.Append("Delete From Base_UserGroupRight Where UserGroup_ID =@UserGroup_ID");
        //        SqlParam[] parm = new SqlParam[]
        //        {
        //            new SqlParam("@UserGroup_ID", UserGroup_ID)
        //        };
        //        sqls[0] = sbDelete;
        //        objs[0] = parm;
        //        int index = 1;
        //        for (int i = 0; i < pkVal.Length; i++)
        //        {
        //            string item = pkVal[i];
        //            if (item.Length > 0)
        //            {
        //                StringBuilder sbadd = new StringBuilder();
        //                sbadd.Append("Insert into Base_UserGroupRight(");
        //                sbadd.Append("UserGroupRight_ID,UserGroup_ID,Menu_Id,CreateUserId,CreateUserName");
        //                sbadd.Append(")Values(");
        //                sbadd.Append("@UserGroupRight_ID,@UserGroup_ID,@Menu_Id,@CreateUserId,@CreateUserName)");
        //                SqlParam[] parmAdd = new SqlParam[]
        //                {
        //                    new SqlParam("@UserGroupRight_ID", CommonHelper.GetGuid),
        //                    new SqlParam("@UserGroup_ID", UserGroup_ID),
        //                    new SqlParam("@Menu_Id", item),
        //                    new SqlParam("@CreateUserId", RequestSession.GetSessionUser().UserId),
        //                    new SqlParam("@CreateUserName", RequestSession.GetSessionUser().UserName)
        //                };
        //                sqls[index] = sbadd;
        //                objs[index] = parmAdd;
        //                index++;
        //            }
        //        }
        //        result = (DataFactory.SqlDataBase().BatchExecuteBySql(sqls, objs) >= 0);
        //    }
        //    catch
        //    {
        //        result = false;
        //    }
        //    return result;
        //}

        //#endregion

        /// <summary>
        /// 文件权限
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List<FileRightsInfo> QueryRoleTreeRights(string userId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select  a.tree_id,max(a.filelevel) as filelevel from base_roletree a inner join base_userrole b
                on a.roles_id=b.roles_id where b.user_id=:p_user_id  group by a.tree_id");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                delegate
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "user_id").ToArray();
                });

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmd.SetParamValues(userId);
            List<FileRightsInfo> list = DbManager.GetInfoList<FileRightsInfo>(cmd,
                delegate(out FileRightsInfo user, DataRow row)
                {
                    user = new FileRightsInfo
                    {
                        ObjID = ParseHelper.Parse<string>(row["tree_id"]),
                        RightsLevel = ParseHelper.Parse<int>(row["filelevel"])
                    };
                });
            return list;
        }

        public bool UserInfoUpdateSpaceStatus(Base_UserInfoSpaceStatusCond cond)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@" update  base_userinfo set space_status=:p_space_status  where user_id=:p_user_id");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                delegate
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "space_status", "user_id").ToArray();
                });

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmd.SetParamValues(cond.SPACE_STATUS,cond.USER_ID);
            return DbManager.ExecNonQuery(cmd)>0;
        }

        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool ResetPassword(Base_ResetPassword cond)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@" update  BASE_USERINFO set user_pwd=:p_user_pwd  where user_id=:p_user_id");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                delegate
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "user_pwd", "user_id").ToArray();
                });

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmd.SetParamValues(cond.password, cond.userId);
            return DbManager.ExecNonQuery(cmd) > 0;
        }

        /// <summary>
        /// 当前用户角色
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public List<Base_RoleInfo> QueryCurrentUserRole(string userid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select b.PARENTID,b.ROLES_ID,b.ROLES_NAME,b.ROLES_REMARK,b.SORTCODE from base_userrole a inner join BASE_ROLES b on a.roles_id=b.roles_id where b.deletemark=1 and  a.user_id=:p_user_id");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                delegate
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "user_id").ToArray();
                });

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmd.SetParamValues(userid);
            List<Base_RoleInfo> list = DbManager.GetInfoList<Base_RoleInfo>(cmd,
                delegate(out Base_RoleInfo user, DataRow row)
                {
                    user = new Base_RoleInfo
                    {
                        PARENTID = ParseHelper.Parse<string>(row["PARENTID"]),
                        ROLES_ID = ParseHelper.Parse<string>(row["ROLES_ID"]),
                        ROLES_NAME = ParseHelper.Parse<string>(row["ROLES_NAME"]),
                        ROLES_REMARK = ParseHelper.Parse<string>(row["ROLES_REMARK"]),
                        SORTCODE = ParseHelper.Parse<int>(row["SORTCODE"])
                    };
                });
            return list;
        }

        /// <summary>
        /// 用户权限
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public Base_FileRoleRightCond GetUserMaxFileRole(string userId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select max(b.see_secr) see_secr,max(b.down_pdf_secr) down_pdf_secr,max(b.down_source_secr) down_source_secr  from base_userrole a inner join BASE_FILEROLERIGHT b on a.roles_id=b.roles_id where a.user_id=:p_user_id");

            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                delegate
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "user_id").ToArray();
                });

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmd.SetParamValues(userId);
            Base_FileRoleRightCond userfile = new Base_FileRoleRightCond();
           userfile=DbManager.GetInfo<Base_FileRoleRightCond>(cmd, delegate(out Base_FileRoleRightCond user, DataRow row) {
                user = new Base_FileRoleRightCond();
                user.DOWN_PDF_SECR = ParseHelper.Parse<int>(row["DOWN_PDF_SECR"]);
                user.DOWN_SOURCE_SECR = ParseHelper.Parse<int>(row["DOWN_SOURCE_SECR"]);
                user.SEE_SECR = ParseHelper.Parse<int>(row["SEE_SECR"]);
            });
           return userfile;
        }
        /// <summary>
        /// 验证密码
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool verifyPassword(Base_UserInfo cond)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from BASE_USERINFO WHERE  USER_ID = '" + cond.USER_ID + "' AND USER_PWD='" + cond.USER_PWD.ToUpper() + "'");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds.Rows.Count>0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool EditStaffUserInfo(Base_UserInfo cond)
        {
            if (cond.USER_PWD != null)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update BASE_USERINFO set USER_PWD = :p_USER_PWD where USER_ID='" + cond.USER_ID+ "'");

                //strSql.Append("USER_SEX = :p_USER_SEX,EMAIL =:p_EMAIL,USER_REMARK = :p_USER_REMARK,TELPHONE = :p_TELPHONE,USER_LANG=:p_USER_LANG where USER_ID=:p_USER_ID");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        //return DbCmdHelper.CreateParameters(dbProvider, "USER_PWD", "USER_SEX", "EMAIL", "USER_REMARK", "TELPHONE", "USER_LANG", "USER_ID").ToArray();
                        return DbCmdHelper.CreateParameters(dbProvider, "USER_PWD").ToArray();
                    });

                cmd.DbCmdInfo.CommandType = CommandType.Text;
                //cmd.SetParamValues(cond.USER_PWD.ToUpper(), cond.USER_SEX, cond.EMAIL, cond.USER_REMARK, cond.TELPHONE, cond.USER_LANG, cond.USER_ID);
                cmd.SetParamValues(cond.USER_PWD.ToUpper());
                return DbManager.ExecNonQuery(cmd) > 0;
            }
            else {
                StringBuilder strSql = new StringBuilder();

                strSql.Append("update BASE_USERINFO set USER_SEX = :p_USER_SEX,EMAIL =:p_EMAIL,USER_REMARK = :p_USER_REMARK,TELPHONE = :p_TELPHONE,USER_LANG=:p_USER_LANG where USER_ID=:p_USER_ID");
                DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "USER_SEX", "EMAIL", "USER_REMARK", "TELPHONE", "USER_LANG", "USER_ID").ToArray();
                    });

                cmd.DbCmdInfo.CommandType = CommandType.Text;
                cmd.SetParamValues(cond.USER_SEX, cond.EMAIL, cond.USER_REMARK, cond.TELPHONE, cond.USER_LANG, cond.USER_ID);
                return DbManager.ExecNonQuery(cmd) > 0;
            }
            return false;
        }

        public bool FeedbackAdd(Base_FeedBackInfo cond)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@" insert into BASE_FEEDBACK(USER_ID, USER_NAME, FEEDBACK_TYPE, FEEDBACK_TITLE, FEEDBACK_CONTENT,FEEDBACK_ATTACHTYPE,FEEDBACK_ATTACHNAME,FEEDBACK_ATTACHURL)
                           values(:p_USER_ID, :p_USER_NAME, :p_FEEDBACK_TYPE, :p_FEEDBACK_TITLE, :p_FEEDBACK_CONTENT,:p_FEEDBACK_ATTACHTYPE,:p_FEEDBACK_ATTACHNAME,:p_FEEDBACK_ATTACHURL)");


            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                delegate
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "USER_ID", "USER_NAME","FEEDBACK_TYPE","FEEDBACK_TITLE","FEEDBACK_CONTENT","FEEDBACK_ATTACHTYPE","FEEDBACK_ATTACHNAME","FEEDBACK_ATTACHURL").ToArray();
                });

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmd.SetParamValues(cond.USER_ID,cond.USER_NAME,cond.FEEDBACK_TYPE,cond.FEEDBACK_TITLE,cond.FEEDBACK_CONTENT,cond.FEEDBACK_ATTACHTYPE,cond.FEEDBACK_ATTACHNAME,cond.FEEDBACK_ATTACHURL);
            return DbManager.ExecNonQuery(cmd)>0;
        }

        /// <summary>
        /// 删除反馈意见
        /// </summary>
        /// <param name="feedback_id"></param>
        /// <returns></returns>
        public bool DelFeedBack(string feedback_id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@" delete from BASE_FEEDBACK where feedback_id=:p_feedback_id");

            feedback_id = System.Text.RegularExpressions.Regex.Replace(feedback_id, @"[^\d{2}-]*", "");
            feedback_id = feedback_id.Replace('{',' ');
            feedback_id = feedback_id.Replace('}', ' ');
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString(),
                delegate
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "feedback_id").ToArray();
                });

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            cmd.SetParamValues(feedback_id);
            //DataTable dt = GetModelBySql(feedback_id);
            //string FEEDBACK_ATTACHURL = "";
            //if (dt.Rows.Count > 0)
            //{
            //    FEEDBACK_ATTACHURL = "~/attach/feedback/" + dt.Rows[0]["FEEDBACK_ATTACHURL"].ToString();
            //}

            if (DbManager.ExecNonQuery(cmd) > 0)
            {
               // File.Delete(FEEDBACK_ATTACHURL);
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 反馈类型
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool SaveFeadbackAuthority(Base_TableAuthorityCond cond)
        {
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "update base_feedback set authority=:p_authority where FEEDBACK_ID=:p_table_id",
                    delegate()
                    {
                        return DbCmdHelper.CreateParameters(dbProvider, "authority", "table_id").ToArray();
                    });
            cmd.SetParamValues(cond.authority, cond.tableid);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            return DbManager.ExecNonQuery(cmd) > 0;
        }
        /// <summary>
        /// 获取反馈列表
        /// </summary>
        /// <param name="FileID">文件ID</param>
        /// <returns>反馈列表</returns>
        public DataTable GetModelBySql(string feedback_id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from BASE_FEEDBACK WHERE  feedback_id = ' " + feedback_id + "'");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;

        }

        public List<Base_FeedBackInfo> QueryFeedbackInfoList(Base_FeedbackCond cond, PageInfo page, OrderInfo order)
        {
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, " sp_getpagefeedbacklist", delegate
            {
                return DbCmdHelper.CreateParameters(dbProvider, true, "begindate", "enddate", "userid", "feedbacktype", "state").ToArray();
            });
            cmd.SetParamValues(order, page,cond.begindate,cond.enddate,cond.userid,cond.feedbacktype,cond.state);
            List<Base_FeedBackInfo> feedbacklist = DbManager.GetPageInfos(cmd, page,
                delegate(out Base_FeedBackInfo feedbackinfo, DataRow row)
                {
                    feedbackinfo = new Base_FeedBackInfo
                    {
                        USER_ID = ParseHelper.Parse<string>(row["USER_ID"]),
                        USER_NAME = ParseHelper.Parse<string>(row["USER_NAME"]),
                        FEEDBACK_TITLE = ParseHelper.Parse<string>(row["FEEDBACK_TITLE"]),
                        FEEDBACK_ID = ParseHelper.Parse<int>(row["FEEDBACK_ID"]),
                        CREATEDATE = ParseHelper.ParseDateTimeToStr(ParseHelper.Parse<DateTime>(row["createdate"])),
                        FEEDBACK_TYPE = ParseHelper.Parse<int>(row["FEEDBACK_TYPE"]),
                        FEEDBACK_ATTACHTYPE = ParseHelper.Parse<string>(row["FEEDBACK_ATTACHTYPE"]),
                        FEEDBACK_ATTACHNAME = ParseHelper.Parse<string>(row["FEEDBACK_ATTACHNAME"]),
                        FEEDBACK_ATTACHURL = ParseHelper.Parse<string>(row["FEEDBACK_ATTACHURL"]),
                        FEEDBACK_CONTENT = ParseHelper.Parse<string>(row["FEEDBACK_CONTENT"]),
                        itemname = ParseHelper.Parse<string>(row["itemname"]),
                        itemvalue = ParseHelper.Parse<int>(row["itemvalue"])
                    };
                });
            return feedbacklist;
        }
    }
}
